package com.xujl.mvcbind.ui.main.control;

import android.os.Bundle;
import android.view.View;

import com.xujl.fastlib.base.BaseFragment;
import com.xujl.mvcbind.R;
import com.xujl.mvcbind.adapter.MainAdapter;
import com.xujl.mvcbind.ui.main.model.MainFragmentModel;
import com.xujl.mvcbind.ui.main.view.MainFragmentView;

/**
 * <pre>
 *     author : xujl
 *     e-mail : 597355068@qq.com
 *     time   : 2019/08/20
 *     desc   : 主要菜单
 *     version: 1.0
 * </pre>
 */

public class MainFragmentControl extends BaseFragment<MainFragmentModel, MainFragmentView> {
    private MainAdapter mAdapter;

    public static MainFragmentControl newInstance () {
        Bundle args = new Bundle();
        MainFragmentControl fragment = new MainFragmentControl();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected void init (Bundle savedInstanceState) {
        mAdapter = new MainAdapter(mModel.getDataList(), exposeActivity());
        mView.setAdapter(mAdapter);
        mView.bindModel(mModel);
    }

    @Override
    public void onClick (View view) {
        super.onClick(view);
        switch (view.getId()) {
            case R.id.btn_search:
                mAdapter.setKeyword(mModel.keyword.get());
                mAdapter.notifyDataSetChanged();
                mView.smoothScrollToPosition(mModel.getKeywordPosition());
                break;
            default:

                break;

        }
    }
}
